//
//  SECViewController.m
//  作业
//
//  Created by 刘崇 on 16/10/13.
//  Copyright © 2016年 刘崇. All rights reserved.
//

#import "SECViewController.h"
#import "ClassModel.h"
#import "Data.h"


@interface SECViewController ()
{
    ClassModel * _classxx;
}
@property (weak, nonatomic) IBOutlet UILabel *chengcai;
@property (weak, nonatomic) IBOutlet UILabel *kouhao;
@property (weak, nonatomic) IBOutlet UILabel *weiji;
@property (weak, nonatomic) IBOutlet UIImageView *imagev;
@property (nonatomic,strong)UIButton *but;
@end

@implementation SECViewController
#define SEC_URL @"http://127.0.0.1/zuoye2.xml"
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(tongzhi:) name:@"Banjixinxi" object:nil];
    [[Data sharedData] shujuchuli:SEC_URL andBJ:self.name];
    //返回按钮
    [self.view addSubview:self.but];
}
//懒加载
-(UIButton *)but
{
    if (!_but)
    {
        _but = [[UIButton alloc]initWithFrame:CGRectMake(10, 20, 60, 20)];
    }
    [_but setTitle:@"返回" forState:UIControlStateNormal];
    [_but setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [_but addTarget:self action:@selector(butcliked) forControlEvents:UIControlEventTouchUpInside];
    return _but;
}
//返回响应方法
-(void)butcliked
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
//通知方法
-(void)tongzhi:(NSNotification*)noti
{
    _classxx = noti.object;
    self.chengcai.text = _classxx.chengcai;
    self.weiji.text = _classxx.kouhao;
    self.kouhao.text = _classxx.weiji;
    NSURL * uurl = [NSURL URLWithString:_classxx.name];
    NSURLRequest *request = [NSURLRequest requestWithURL:uurl];
    NSData * data =[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    UIImage *imag = [[UIImage alloc]initWithData:data];
    self.imagev.image = imag;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
